#include "llcomp_llc.h" 

    

        typedef  struct {  double creal;  double cimag;}  complex;
     
     void loopParallelFor0_support(  complex *c,  complex *_z,  int *_i,  double *_ztemp,  int *_numoutside,  int *_j) ;
     void loopParallelFor0_support(  complex *c,  complex *_z,  int *_i,  double *_ztemp,  int *_numoutside,  int *_j)  {
                 complex z = *_z;
                 int i = *_i;
                 double ztemp = *_ztemp;
                 int numoutside = *_numoutside;
                 int j = *_j;
        /* Begin template: forall_init_unit.tmpl */

/* $0 => Variable del bucle
 * loop_initial => Valor inicial de la variable del bucle B
 * loop_finalice => Valor final de la variable del bucle C
 */

{
    int llc_meanT, llc_rnT;
    register int llc_i;

    llc_nT = ((4092 - 1) - (0) + 1);
    /* Medium number of tasks */
    llc_meanT = llc_nT / LLC_NUMPROCESSORS;
    /* Number of unassigned tasks */
    llc_rnT = llc_nT % LLC_NUMPROCESSORS;

    LLC_CHECK_MALLOC (llc_F, (LLC_NUMPROCESSORS + 1), int);

    llc_F[0] = 0;
    for (llc_i = 1; llc_i < (LLC_NUMPROCESSORS + 1); llc_i++) {
        llc_F[llc_i] = llc_F[llc_i-1] + llc_meanT + (((llc_i - 1) < llc_rnT) ? 1 : 0);
    }
}

/* End template: forall_init_unit.tmpl */
/* Begin template: forall_exec_unit.tmpl */

/* loop_var => Variable del bucle
 * loop_initial => Valor inicial de la variable del bucle
 * loop_stmt => Bloque del bucle
 */

{
    int llc_nP;
    int llc_grp_save;
    register int llc_i;

    llc_nP = LLC_NUMPROCESSORS;
    llc_grp_save = LLC_NAME;
    LLC_NUMPROCESSORS = 1;
    LLC_NAME = 0;
    
    i = (0) + llc_F[llc_grp_save];
    for (llc_i = 0; llc_i < LLC_PROCSGRP(llc_grp_save); llc_i++, i++) {
        
{

z.creal = c[i].creal ;
z.cimag = c[i].cimag ;
  for (j= 0; j < 100000; (j++ ))  
{

ztemp= ((z.creal  * z.creal ) - (z.cimag  * z.cimag )) + c[i].creal ;
z.cimag = ((z.creal  * z.cimag ) * 2) + c[i].cimag ;
z.creal = ztemp;
    if     (    ((z.creal  * z.creal ) + (z.cimag  * z.cimag )    ) > 2.0    )     
{

      (numoutside++       );
      break ;
    }

;
  }

 ;
}

;
    }

    LLC_NAME = llc_grp_save;
    LLC_NUMPROCESSORS = llc_nP;
}

/* End template: forall_exec_unit.tmpl */
/* Begin template: forall_comm_red.tmpl */

{
    register int llc_i;
    int llc_buf_size = 0;
    char *llc_buf = NULL, *llc_buf_ptr = NULL, *llc_buf_tmp = NULL;
    MPI_Status llc_status;

    llc_buf_size += sizeof (int );
 

    if (llc_buf_size > 0) {
        
        LLC_CHECK_MALLOC (llc_buf, llc_buf_size, char);

        if (LLC_NAME == 0) {
            for (llc_i = 1; llc_i < LLC_NUMPROCESSORS; llc_i++) {
                MPI_Recv (llc_buf, llc_buf_size, MPI_BYTE, llc_i, LLC_TAG_REDUCE_DATA, *llc_CurrentGroup, &llc_status);
                llc_buf_ptr = llc_buf;

numoutside += (*(int  *) llc_buf_ptr);
llc_buf_ptr +=  sizeof(int );
 
            }

            llc_buf_ptr = llc_buf;

memcpy (llc_buf_ptr, &numoutside, sizeof(int ));
llc_buf_ptr += sizeof(int );
 
            
            MPI_Bcast (llc_buf, llc_buf_size, MPI_BYTE, 0, *llc_CurrentGroup);
        }
        else {
            llc_buf_ptr = llc_buf;

memcpy (llc_buf_ptr, &numoutside, sizeof(int ));
llc_buf_ptr += sizeof(int );
 
            
            MPI_Send (llc_buf, llc_buf_size, MPI_BYTE, 0, LLC_TAG_REDUCE_DATA, *llc_CurrentGroup);
            MPI_Bcast (llc_buf, llc_buf_size, MPI_BYTE, 0, *llc_CurrentGroup);
            
            llc_buf_ptr = llc_buf;

memcpy (&numoutside, llc_buf_ptr, sizeof(int ));
llc_buf_ptr += sizeof(int );

        }	

        free (llc_buf);
        free (llc_buf_tmp);
    }
}

/* End template: forall_comm_red.tmpl */
/* Begin template: forall_exit.tmpl */

    free(llc_F);
    llc_F = NULL;

/* End template: forall_exit.tmpl */

                *_z = z;
                *_i = i;
                *_ztemp = ztemp;
                *_numoutside = numoutside;
                *_j = j;

    }

    